import { EngineObject } from "@/EngineObject";
import { ESSceneObject } from "@/ESObjects";
import { ESViewer } from "@/ESViewer";
import { JsonValue } from "xbsj-base";
import { Property } from "../props";
import { SceneTreeJsonValue } from "@/ESObjectManager/SceneTrees";

/**
 *  @description 视口状态，'Raw'初始状态，'Creating'正在创建, 'Created'创建完成, 'Error'创建失败，'Reconnecting'重新连接中
 */
export type ViewerStatus = 'Raw' | 'Creating' | 'Created' | 'Error' | 'Reconnecting';

/**
 * @example [116.397428, 39.90923]
 */
export type ESJVector2D = [number, number];

/**
 * @example [[1,2],[3,4]]
 */
export type ESJVector2DArray = ESJVector2D[];

/**
 * @example [116.397428, 39.90923 ,100]
 */
export type ESJVector3D = [number, number, number];

/**
 * @example [[1,2,3],[4,5,6]]
 */
export type ESJVector3DArray = ESJVector3D[];

/**
 * @example [-180, -90, 180, 90]
 */
export type ESJVector4D = [number, number, number, number];

/**
 * @example [[1,2,3,4],[5,6,7,8]]
 */
export type ESJVector4DArray = ESJVector4D[];

/**
 * @description 颜色类型
 * @example r,g,b为[0,255] 映射到 0~1 , a为[0,1],例如[1, 0, 0, 1] 表示红色;
 */
export type ESJColor = [r: number, g: number, b: number, a: number];

/**
 * @description 渲染类型 真实世界类型 和 屏幕像素类型
 */
export type ESJRenderType = "world" | "screen"
/**
 *  @description 点样式
 */
export type ESJPointStyle = { size: number; sizeType: ESJRenderType; color: ESJColor; material: string; materialParams: JsonValue; }
/**
 *  @description 线样式
 */
export type ESJStrokeStyle = { ground: boolean, width: number; widthType: ESJRenderType; color: ESJColor; material: string, materialParams: JsonValue }
/**
 * @description  面样式
 */
export type ESJFillStyle = { ground: boolean, color: ESJColor, material: string; materialParams: JsonValue; }

/**
 * @description  flyTo参数
 * @param distance 相机距离目标点的距离
 * @param heading 相机朝向目标点的方向
 * @param pitch 相机俯仰角
 * @param flyDuration 飞行时间
 * @param hDelta 相机水平偏移量
 * @param pDelta 相机垂直偏移量
 */
export type ESJFlyToParam = { distance: number, heading: number, pitch: number, flyDuration: number, hDelta: number, pDelta: number };

/**
 * @description  flyIn参数
 * @param position 相机位置
 * @param rotation 相机旋转
 * @param flyDuration 飞行时间
 */
export type ESJFlyInParam = { position: ESJVector3D, rotation: ESJVector3D, flyDuration: number };

/**
 * @description pick拾取信息体
 */
export interface ESJPickedInfo { attachedInfo: any; pickedInfo?: ESJPickedInfo; }


type ESVOption = {
    container: HTMLDivElement | string;
    type: string;
    id?: string;
    options?: JsonValue
}

export type ESVOptionUeUri = {
    type: 'ESUeViewer';
    container: HTMLDivElement | string;
    id?: string;
    options: {
        uri: string,
        app: string,
        token?: string,
    }
}
export type ESVOptionUeWs = {
    type: 'ESUeViewer';
    container: HTMLDivElement | string;
    id?: string;
    options: {
        ws: string;
        esmsg?: string;
    }
}
type ESVOptionCzm = {
    type: 'ESCesiumViewer';
    id?: string
    container: HTMLDivElement | string;
    options?: JsonValue;
}
type ESVOptionUe = ESVOptionUeUri | ESVOptionUeWs;

export { ESVOption, ESVOptionCzm, ESVOptionUe };


export type ESJViewInfo = {
    viewDistance?: number | undefined,
    duration?: number | undefined,
    position: [number, number, number],
    rotation?: [number, number, number] | undefined,
    thumbnail?: string | undefined,
    name?: string | undefined
}

export type ViewerObjsMap = Map<string, new (option: ESVOption) => ESViewer>;
export type EngineObjsMap = Map<string, new (sceneObject: ESSceneObject, viewer: ESViewer) => EngineObject>;

/**
 * @description  属性类型 ,UI上会按照分类展示
 * @type {ESJProperty}
 * @param basic 基础属性
 * @param general 通用属性
 * @param dataSource 数据源属性
 * @param location 位置属性
 * @param coordinate 坐标属性
 * @param style 样式属性
 */
export type ESPropertiesType = {
    basic: Property[];
    general: Property[];
    dataSource: Property[];
    location: Property[];
    coordinate: Property[];
    style: Property[];
}

export type ESJsonObjectType = { [key: string]: any }


/**
 *   @param DECIMAL_DEGREE   度格式，dd.ddddd°
 *   @param DEGREES_DECIMAL_MINUTES  度分格式，dd°mm.mmm'
 *   @param SEXAGESIMAL_DEGREE  度分秒格式，dd°mm'ss"
 */
export type ESJLonLatFormatType = 'DECIMAL_DEGREE' | 'DEGREES_DECIMAL_MINUTES' | 'SEXAGESIMAL_DEGREE'

/**
 * @description 基础状态信息
 * @type {ESJBasicInfoType}
 * @param fps 帧率
 * @param position 相机位置
 * @param rotation 相机姿态
 * @param length 比例尺
 */
export type ESJStatusInfoType = {
    fps: number;
    position: [number, number, number];
    rotation: [number, number, number];
    length: number;
}

/**
 * @description 导航模式
 * @type {ESJNavigationMode}
 * @param Map 地图模式
 * @param Walk 步行模式
 * @param Line 线路模式
 * @param UserDefined 自定义模式
 * @param RotateGlobe 旋转地球模式
 * @param RotatePoint 旋转点模式
 * @param Follow 跟随模式
 */
export type ESJNavigationMode = "Map" | "Walk" | "Line" | "UserDefined" | "RotateGlobe" | "RotatePoint" | "Follow";


export type ESObjectsManagerJsonType = {
    asset: {
        type: string;
        version: string;
        createdTime: string;
        modifiedTime: string;
        name: string;
    };
    viewers?: JsonValue,
    sceneTree?: SceneTreeJsonValue;
    viewCollection?: ESJViewInfo[];
    lastView?: ESJViewInfo;
};


export type ESJWidgetEventInfo = {
    type: "leftClick" | "rightClick" | "mouseEnter" | "mouseLeave" | "childMouseLeave" | "childMouseEnter";
    add?: {
        children?: string[];
        mousePos?: [number, number];
    }
}
